package lcr;

public class Test0003 {
}

class Solution0003_1 {
    public int[] countBits(int n) {
        int[] ans = new int[n + 1];
        int lastIndex = 0;

        for (int i = 1; i <= n; i++) {
            if (((i-1)&i)==0){
                lastIndex = i;
            }
            ans[i] = ans[i - lastIndex] + 1;
        }

        return ans;
    }
}
